/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.rational.sheet.table.cell.model;

import org.rational.parser.Parser;
import org.rational.sheet.table.RationalParser;
import org.rational.sheet.table.RationalTableData;

/**
 *
 * @author Overmind
 */
public class CellValue
{    
    private String value;
    private String formula;
    private RationalParser parser;
    
    public CellValue(RationalParser parser)
    {
        this("", parser);
    }
    
    public CellValue(String formula, RationalParser parser)
    {
        this.parser = parser;
        setFormula(formula);
    }
    
    public String getFormula()
    {
        return formula;
    }
    
    public String getValue()
    { 
        return value;
    }
    
    public final void setFormula(String formula)
    {
        this.formula = formula;
        
	if(formula.startsWith("="))
	{
	    String substring = formula.substring(1);
            this.value = parser.parse(substring);
	}
	else
	{
            this.value = formula;
	}
    }
}
